package com.fanxuankai.ksql.function.udf.datetime;

import io.confluent.ksql.function.FunctionCategory;
import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;
import io.confluent.ksql.function.udf.datetime.ConvertTz;

import java.sql.Timestamp;

/**
 * Asia/Shanghai 转为 UTC 时区
 *
 * @author fanxuankai
 */
@UdfDescription(name = "utc", category = FunctionCategory.DATE_TIME, author = "fanxuankai",
        description = "Converts a TIMESTAMP value from Asia/Shanghai to UTC.")
public class Utc {
    private final ConvertTz convertTz = new ConvertTz();

    @Udf(description = "Converts a TIMESTAMP value from Asia/Shanghai to UTC")
    public Timestamp convertTz(@UdfParameter(value = "timestamp", description = "The TIMESTAMP value.") final Timestamp timestamp) {
        return convertTz.convertTz(timestamp, "Asia/Shanghai", "UTC");
    }
}
